Support compact imports in the spec interpreter#18
Open
bvisness wants to merge 1 commit into
Open
Conversation
13139c4 to
1196239
Compare
Adds binary and text parsing support for the compact import section proposal. Also fixes a small section-sizing bug in the binary tests.
1196239 to
e848b7d
Compare
rossberg
reviewed
May 19, 2026
Member
rossberg
left a comment
There was a problem hiding this comment.
Sorry, I have somehow managed to miss this PR entirely!
This looks correct, I only have suggestions for simplifying the code somewhat.
The one thing I wonder is whether the encoder should also make use of the short-hands, similar to how it tries to compactify locals. But we can discuss that separately.
Comment on lines
+1057
to
+1058
| let xt = externtype s in | ||
| [Import (module_name, item_name, xt) @@ region s left (pos s)] |
Member
There was a problem hiding this comment.
You can avoid duplicating this case by replacing the outer if with guards on the cases, like
match peek s with
| Some 0x7f when item_name = [] -> ...
| Some 0x7e when item_name = [] -> ...
| _ -> ...
| { fun c -> | ||
| let (items, xt_fn) = $4 in | ||
| let (id, anon, _bind, df) = xt_fn c in | ||
| (match id with Some x -> error x.at "identifier not allowed" | None -> ()); |
Member
There was a problem hiding this comment.
Suggested change
| (match id with Some x -> error x.at "identifier not allowed" | None -> ()); | |
| Option.iter (fun x -> error x.at "identifier not allowed") id; |
Comment on lines
+1231
to
+1232
| { fun c -> ($3, anon_func, bind_func, | ||
| fun () -> ExternFuncT (Idx ($4 c).it)) } |
Member
There was a problem hiding this comment.
Perhaps this somewhat complicated deferred application and checking can be avoided by passing in a Boolean attribute b that controls whether an id is allowed. Like:
{ fun c b -> ignore ($3 c b anon_func (bind_if b bind_func));
fun () -> ExternFuncT (Idx ($4 c).it) }
where
let bind_if b f = if b then f else fun _c x -> error x.at "identifier not allowed"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds binary and text parsing support for the compact import section proposal.
The text parser is a bit crazy because we need to disallow identifiers when using the second compact encoding form. The actual binding of identifiers has been sort of proxied up to the "caller" as a result. I'm open to suggestions for other ways to structure this, but duplicating all the externtype parsing seemed bad, and I'm no good with Menhir.